// Pixel filter class, added by regret
#ifndef _VID_FILTER_H_
#define _VID_FILTER_H_

// rotate helper
class RotateHelper {
public:
	RotateHelper();
	~RotateHelper();

	bool init();
	void exit();
	void doRotate();

protected:
	unsigned char* image;
	unsigned imgpitch;
	unsigned w, h;
	int rotate;
};

// scanline filter
class ScanlineFilter : public RotateHelper {
public:
	bool enabled;
	unsigned intensity;

	bool init();
	void exit();
	void render(unsigned char*, unsigned int, unsigned char*, unsigned int, unsigned, unsigned);
	void setIntensity(unsigned);
	unsigned int zoom();
	void apply(unsigned char* pd, unsigned dstPitch);
	inline unsigned adjust(unsigned i);

	ScanlineFilter();
	~ScanlineFilter();

private:
	unsigned char* buffer;
};

// Function pointer type for a filter function
typedef void(*FilterFunc)(unsigned char*, unsigned int, unsigned char*, unsigned char*, unsigned int, unsigned, unsigned);

class Filter : public RotateHelper {
public:
	enum FILTER_TYPE {
		FILTER_NONE = 0,
		FILTER_EPXB,
		FILTER_EPXC,
		FILTER_SCALE2X,
		FILTER_SCALE3X,
		FILTER_2XSAI,
		FILTER_SUPER2XSAI,
		FILTER_SUPEREAGLE,
		FILTER_HQ2X,
		FILTER_HQ2XS,
		FILTER_HQ3X,
		FILTER_HQ3XS,

		FILTER_NUMBER,
	};

	int filterId;
	unsigned int linear;
	bool enable;

	void exit();
	int init(int effect, int rotate);
	int scale(RECT* rect, unsigned width, unsigned height);
	int apply(unsigned char* dst, unsigned pitch);

	const wchar_t* name(int effect);
	unsigned int zoom(int effect);
	unsigned int depth(int effect, unsigned depth);

	void select(int effect);
	int getFilter() { return filterEffect; }

	Filter();
	~Filter();

private:
	FilterFunc filterFunction;
	int filterEffect;
};

extern Filter filter;
extern ScanlineFilter scanlineFilter;

#endif
